Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(virtualization): 内核虚拟化支持 #900

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

GnoCiYeH
Copy link
Member

@GnoCiYeH GnoCiYeH commented Aug 27, 2024

主要完成整体框架的搭建以及CPU虚拟化模块。目前能够成功vmlaunch,后续会在这个pr下继续开发。

下列为完成进度以及后续TODO:

  • 整体框架搭建
  • 接入文件系统
  • CPU虚拟化
  • 内存虚拟化
  • IO虚拟化
  • 中断虚拟化

@github-actions github-actions bot added the enhancement New feature or request label Aug 27, 2024
@fslongjin
Copy link
Member

可以先merge一下主线,然后review之后,剩余的功能分多个pr提交

use crate::{
arch::mm::barrier,
kdebug, kerror,
mm::{phys_2_virt, PhysAddr},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不应该依赖这个接口,应改为MMArch::phys_2_virt

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为何,这都已经在x86下了吧

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是旧版的接口,在主线已经被移除了。

Copy link
Member

@fslongjin fslongjin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

然后,对于一些体积较大的结构体,建议在堆上分配,以免爆栈。

}

pub fn vmcs_load(phys_addr: PhysAddr) {
match unsafe { x86::bits64::vmx::vmptrld(phys_addr.data() as u64) } {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

所有类似这种的,都要使用if let Err(e) = xxxx

use crate::{
arch::mm::barrier,
kdebug, kerror,
mm::{phys_2_virt, PhysAddr},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是旧版的接口,在主线已经被移除了。


static mut TDP_ENABLED: bool = false;
static mut TDP_MMU_ENABLED: bool = true;
static mut TDP_MMU_ALLOWED: bool = unsafe { TDP_MMU_ENABLED };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个值得在kvm x86 mmu初始化之后再设置吧?不然的话他一直都是true了。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个值目前只是先给个默认值,后面需要动态调整的时候再调整

VmxAsm::vmx_vmwrite(control::CR4_READ_SHADOW, cr4_flags.bits() as u64);
VmxAsm::vmx_vmwrite(guest::CR4, hw_cr4.bits() as u64);

if (cr4_flags ^ old_cr4).contains(Cr4::CR4_ENABLE_OS_XSAVE | Cr4::CR4_ENABLE_PROTECTION_KEY)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里有问题,你想表达的意思应该是,(cr4_flags ^ old_cr4)的结果,包含Cr4::CR4_ENABLE_OS_XSAVE 或者 Cr4::CR4_ENABLE_PROTECTION_KEY

但是这种写法,指的是,(cr4_flags ^ old_cr4)的结果同时具有Cr4::CR4_ENABLE_OS_XSAVECr4::CR4_ENABLE_PROTECTION_KEY

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

基于linux源码,原有语意是正确的

@dragonosbot dragonosbot added O-x86_64 Target: x86_64 T-virtulization Relevant to the virtulization team, which will review and decide on the PR/issue. labels Aug 30, 2024
}
}

pub struct Pte {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

#[allow(dead_code)]
pub mod kvm_exit {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个写到单独的模块文件好些

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request O-x86_64 Target: x86_64 T-virtulization Relevant to the virtulization team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants